﻿var ns, toast, actionsheet,imageBrowser, WXPhotoPicker, docReader, fileBrowser;
var app = new Vue({
    el: '#app',
    data: {
        form:{
            radioValue:'1',
            StaffID:0,
            startHourTime:moment().format('YYYY-MM-DD HH:mm'),
            endHourTime:moment().format('YYYY-MM-DD HH:mm'),
            startTime:moment().format('YYYY-MM-DD'),
            endTime:moment().format('YYYY-MM-DD'),
            hoursNum:0,
            daysNum:0,
        },
        chooseType: 1,
        show: false,
        showup:false,
        showTime:false,//是否开始时间（带小时）
        showOverTime:false,//是否结束时间（带小时）
        showdayTime:false,//是否开始时间（日期）
        showOverdayTime:false,//是否结束时间（日期）
        leave:{
            timer:new Date(),
            overTimer:new Date(),
            day:new Date(),
            overDay:new Date(),
        },
        writeCount: 0,//输入的文字数量
        examine_writenum: 0,//审批原因字数
        wenjianlist: [],
        imgindex: 0,
        img_count: 0,
        select_imglist: [],
        select_imgindex: 0,
        maxuploadcount: CONFIG.maxuploadcount,
        outTypemsg: [],
        // file: {
        //     ID: 0,
        //     CredentialName: '',
        //     CredentialUrl: '',
        //     TypeName:'',
        // },
        tdRemark:'',//请假原因
        VisitType:0,//请假类型ID
        VisitTypeName:'',//请假类型
        Remark:'',//审批申请说明
        ApprovalUserID: [],//审批人
        SendUserIDs: [],//抄送人
        fileList:[],//文件id
        select_id_list: [],//选中的抄送人员(多选)
        choose_id_list: [],//选中的审批人员(单选)
        fileID: 1,
        //审批-附件
        exshowup: false,
        exmaxuploadcount: CONFIG.maxuploadcount,
        exUploadList: [],
        exFileList: [],
    },
    methods: {
        // 选择用印类型
        do_choose_type: function () {
            var that = this;
            that.show = true;
        },
        get_outTypemsg: function () {
            var that = this;
            var options = {};
            options.action = 'getuserstaffsysdefinefield';
            options.Type='12';
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.status) {
                        that.outTypemsg = data.List;
                        that.VisitType = data.List[0].Id;
                        that.VisitTypeName = data.List[0].FieldName;
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_choose_startTime:function(type){
            var that=this;
            if(type==1){
                that.showTime=true;
            }else{
                that.showOverTime=true;
            }
        },
        onConfirmStartHours:function(value){
            var that=this;
            var a=moment(value);
            var b=moment(that.form.endHourTime);
            var num=b.diff(a,'hours');
            if(num<0){
                api.toast({
                    msg: '开始时间不能大于结束时间',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            that.form.startHourTime=moment(value).format("YYYY-MM-DD HH:mm");
            that.form.hoursNum=num;
            that.showTime=false;
        },
        onConfirmEndHours:function(value){
            var that=this;
            var a=moment(that.form.startHourTime);
            var b=moment(value);
            var num=b.diff(a,'hours');
            // return;
            if(num<0){
                api.toast({
                    msg: '结束时间不能小于开始时间',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            that.form.endHourTime=moment(value).format("YYYY-MM-DD HH:mm");
            that.form.hoursNum=num;
            that.showOverTime=false;
        },
        do_choose_startdayTime:function(type){
            var that=this;
            if(type==1){
                that.showdayTime=true;
            }else{
                that.showOverdayTime=true;
            }
        },
        onConfirmStart:function(value){
            var that=this;
            var a=moment(value);
            var b=moment(that.form.endTime);
            var num=b.diff(a,'days');
            if(num<0){
                api.toast({
                    msg: '开始日期不能大于结束日期',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            that.form.startTime=moment(value).format("YYYY-MM-DD");
            that.form.daysNum=num;
            that.showdayTime=false;
        },
        onConfirmEnd:function(value){
            var that=this;
            var a=moment(that.form.startTime);
            var b=moment(value);
            var num=b.diff(a,'days');
            if(num<0){
                api.toast({
                    msg: '结束日期不能小于开始日期',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            that.form.endTime=moment(value).format("YYYY-MM-DD");
            that.form.daysNum=num;
            that.showOverdayTime=false;
        },
        // 选择用印类型
        doSelectRoom: function (item) {
            var that = this;
            that.show = false;
            that.VisitType = item.Id;
            that.VisitTypeName = item.FieldName;
        },
        //用印原因限制字数
        writeMsg: function () {
            var that = this;
            var testVal = that.tdRemark.length;
            that.writeCount = testVal;

        },
        //审批申请限制字数
        examine_writeMsg: function () {
            var that = this;
            that.examine_writenum = that.Remark.length;
        },
        //上传附件
        do_openUp:function(){
            var that=this;
            that.showup=true;
        },
        //上传图片
        add_picture: function () {
            var that = this;
            that.showup=false;
            ns.confirmPer('camera', function () {
                that.choose_picture_start();
            })
        },
        choose_picture_start:function(){
            var that = this;
            if (that.wenjianlist.length >= that.maxuploadcount) {
                api.toast({
                    msg: '最多支持' + that.maxuploadcount + '张图片',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.actionSheet({
                cancelTitle: '取消',
                buttons: ['拍照', '从相册选择']
            }, function(ret, err) {
                //拍照
                if(ret.buttonIndex==1){ 
                    that.upload_choose_picture();
                    return;
                }
                //从相册选择
                if(ret.buttonIndex==2){
                    that.choose_picture_album();
                    return;
                } 
                //取消 
                else{
                    return false;  
                }  
            });
        },
        upload_choose_picture:function(){
            var that = this;
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'jpg',
                destinationType: 'url',
                allowEdit: false,
                saveToPhotoAlbum: true,
            }, function(ret, err) {
                if (ret&&ret.data) {
                    var list = [];
                    list.push({
                        url: ret.data,
                    });
                    const params = {
                        action: "uploaduserstaffinfo",
                        Type:6
                    }
                    ns.post(params, function (succeed, data, err) {
                        if (succeed) {
                            // that.file.ID = data.file.ID;
                            // that.file.CredentialName = data.file.FileName;
                            // that.file.CredentialUrl = data.file.FullPath;
                            if(data.imgs.length>0){
                                that.wenjianlist.push(data.imgs[0]);
                            }
                            // that.file.TypeName= data.file.ContentType;
                            // console.log(JSON.stringify(that.wenjianlist));
                        }
                    }, {
                        files: {
                            file: list[0].url
                        }
                    })
                } 
            });
        },
        choose_picture_album:function(){
            var that = this;
            WXPhotoPicker.open({
                max: that.maxuploadcount - that.wenjianlist.length,
                type:'image',
            }, function(ret) {
                if (ret) {
                    if (ret.list.length > 0) {
                        ret.list.forEach((item) => {
                            var list = [];
                            list.push({
                                url: item.path,
                            });
                            const params = {
                                action: "uploaduserstaffinfo",
                                Type:6
                            }
                            ns.post(params, function (succeed, data, err) {
                                if (succeed) {
                                    if(data.imgs.length>0){
                                        that.wenjianlist.push(data.imgs[0]);
                                    }
                                }
                            }, {
                                files: {
                                    file: list[0].url
                                }
                            })
                        });
                    }
                }
            });
        },
        //上传文件
        add_wenjian: function () {
            var that = this;
            that.showup=false;
            fileBrowser.open({
                confirm: true
            }, function (ret) {
                fileBrowser.close();
                // alert(JSON.stringify(ret))
                // alert(JSON.stringify(ret && ret.status))
                if (ret) {
                    const url = ret.url || ""
                    var i = url.lastIndexOf('.');
                    var j = url.length;
                    var wenjianName = url.slice(i + 1, j);
                    // alert(JSON.stringify(wenjianName));
                    // that.form.wenjianUrl = url;
                    // alert(JSON.stringify(that.form.wenjianUrl));
                    // that.wenjianlist.push({ id: that.fileID, name: that.form.wenjianName, url: that.form.wenjianUrl });
                    // that.fileID++
                    // alert(JSON.stringify(that.wenjianlist));
                    // 多规格图片上传
                    const params = {
                        action: "uploaduserstaffinfo",
                        Type:6
                    }
                    // alert("url----"+JSON.stringify(url))
                    ns.post(params, function (succeed, data, err) {
                        if (succeed) {
                            // that.file.ID = data.imgs[0].ID;
                            // that.file.CredentialName = data.imgs[0].FileName;
                            // that.file.CredentialUrl = data.imgs[0].FilePath;
                            that.wenjianlist.push(data.imgs[0]);
                            // var i = that.file.CredentialName.lastIndexOf('.');
                            // var j = that.file.CredentialName.length;
                            // that.file.TypeName= that.file.CredentialName.slice(i + 1, j);
                            // that.fileList.push(data.imgs[0].ID);
                            // alert(JSON.stringify(that.fileList))
                            
                        }
                    }, {
                        files: {
                            file: [url]
                        }
                    })
                    return;
                }
                return false;
            });
        },
        open_flie: function (item,index) {
            var that = this;
            var i = item.FileName.lastIndexOf('.');
            var j = item.FileName.length;
            var nameType= item.FileName.slice(i + 1, j);
            if(nameType=='png'||nameType=='jpg'||nameType == 'jpeg'||nameType=='tif'||nameType=='gif'){
                that.img_browser(item.FilePath);
            }else{
                that.do_openFile(item);
            }
            
        },
        // do_viewimages: function (activeIndex) {
        //     var that = this;
        //     var imageUrls = [];
        //     var list=[];
        //     list = that.wenjianlist.filter((item) => {
        //         return item.type=='picture'
        //         });
        //     for (var i = 0; i < list.length; i++) {
        //         imageUrls.push(list[i].url);
        //     }
        //     var imageBrowser = api.require('imageBrowser');
        //     imageBrowser.openImages({
        //         showList: false,
        //         activeIndex: activeIndex,
        //         imageUrls: imageUrls
        //     });
        // },
        img_browser: function(imgurl) {
            var that = this;
            var imgurls = [];
            imgurls.push(imgurl);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        do_openFile:function(item){
            api.download({
                url: item.FilePath,
                savePath: 'fs://app/' + item.FileName,
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {
                if (ret.state == 1) {
                    docReader.open({
                        path: ret.savePath,
                        autorotation: false
                    }, function(ret, err) {
                        if (ret.status) {
                            // alert(JSON.stringify(ret));
                        } else {
                            alert(JSON.stringify(err));
                        }
                    });
                }else{
                    api.toast({
                        msg: '打开失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        //删除文件
        do_delete: function (id) {
            var that=this;
            that.wenjianlist = that.wenjianlist.filter((item) => {
                return item.ID != id
            });
            // var options={};
            // options.ID=id;
            // options.action="delfile"
            // ns.post(options, function (succeed, data, err) {
            //     console.log(JSON.stringify(data));
            //     console.log(JSON.stringify(err));
            //     if(succeed){
            //         if(data.status){
            //             console.log(JSON.stringify(that.wenjianlist));
            //             that.wenjianlist = that.wenjianlist.filter((item) => {
            //                 return item.ID != id
            //             });
            //         }

            //     }else{
            //         api.toast({
            //             msg: err,
            //             duration: 2000,
            //             location: 'bottom'
            //         });
            //     }
            // });
        },
        //提交
        do_save: function () {
            var that = this;
            var SendUserIDs = [];

            if (that.VisitTypeName == "") {
                api.toast({
                    msg: '请选择请假类型',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }

            // if (that.Number == 0) {
            //     api.toast({
            //         msg: '请填写用印次数',
            //         duration: 2000,
            //         location: 'bottom'
            //     });
            //     return;
            // }
            // if (that.tdTitle=='') {
            //     api.toast({
            //         msg: '请填写用印标题',
            //         duration: 2000,
            //         location: 'bottom'
            //     });
            //     return;
            // }
            if (that.tdRemark=='') {
                api.toast({
                    msg: '请填写请假原因',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            if (that.choose_id_list.length <= 0) {
                api.toast({
                    msg: '请选择审批人',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            var VacationStartTime='';
            var VacationEndTime='';
            var VacationPeriod='';
            if(that.form.radioValue==1){
                if(!that.form.startHourTime){
                    api.toast({
                        msg: '请选择开始时间',
                        duration: 2000,
                        location: 'bottom'
                    });
                    return;
                }
                if(!that.form.endHourTime){
                    api.toast({
                        msg: '请选择结束时间',
                        duration: 2000,
                        location: 'bottom'
                    });
                    return;
                }
                VacationStartTime=that.form.startHourTime;
                VacationEndTime=that.form.endHourTime;
                VacationPeriod=that.form.hoursNum;
            }else if(that.form.radioValue==2){
                if(!that.form.startTime){
                    api.toast({
                        msg: '请选择开始日期',
                        duration: 2000,
                        location: 'bottom'
                    });
                    return;
                }
                if(!that.form.endTime){
                    api.toast({
                        msg: '请选择结束日期',
                        duration: 2000,
                        location: 'bottom'
                    });
                    return;
                }
                VacationStartTime=that.form.startTime;
                VacationEndTime=that.form.endTime;
                VacationPeriod=that.form.daysNum;
            }
            for (var i = 0; i < that.wenjianlist.length; i++) {
                var item = that.wenjianlist[i].ID;
                that.fileList.push(item);
            }
            for (var i = 0; i < that.choose_id_list.length; i++) {
                var item = that.choose_id_list[i].UserID;
                that.ApprovalUserID.push(item);
            }
            for (var i = 0; i < that.select_id_list.length; i++) {
                var item = that.select_id_list[i].UserID;
                SendUserIDs.push(item);
            }
            //审批-附件
            that.exFileList=[];
            for (var i = 0; i < that.exUploadList.length; i++) {
                var item = that.exUploadList[i].ID;
                that.exFileList.push(item);
            }

            that.SendUserIDs = JSON.stringify(SendUserIDs);
            var options={};
            options.UserIDList=JSON.stringify(that.ApprovalUserID);
            options.SendUserIDList=that.SendUserIDs;
            options.Type=6;
            options.StaffID=that.form.StaffID;
            options.VacationTypeId=that.VisitType;
            options.VacationType=that.VisitTypeName;
            options.VacationTimerType=that.form.radioValue;
            options.VacationStartTime=VacationStartTime;
            options.VacationEndTime=VacationEndTime;
            options.VacationPeriod=VacationPeriod;
            options.Remark=that.tdRemark;
            options.AuditRemark=that.Remark;
            options.fileList=JSON.stringify(that.fileList);
            options.exFileList = JSON.stringify(that.exFileList);
            options.action='saveandpushaudituserstafftransfer';
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    api.toast({
                        msg: '提交成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    api.sendEvent({
                        name: 'purchase_updata',
                    });
                    api.sendEvent({
                        name:'reloadexaminelist'
                    })
                    setTimeout(() => {
                        api.closeWin();
                    }, 400);

                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        //展开选择的全部人员
        open_more: function (type) {
            var that = this;
            //审批全部
            if (type == 1) {
                ns.openWin('examine_Allperson', '全部审批人员', {
                    list: that.choose_id_list,
                    type: type,
                });
            } else if (type == 0) {
                ns.openWin('examine_Allperson', '全部抄送人员', {
                    list: that.select_id_list,
                    type: type,
                });
            }

        },

        //选择人
        choose_persons: function (IsApproval) {
            var that = this;
            that.chooseType = IsApproval;
            // IsApproval==0//抄送
            if (IsApproval == 0) {
                // ns.openWin('chooseperson_frm', '请选择', {
                //     source: 'transfer',
                // });
                ns.openWin('chooseuser_frm', '选择抄送人', {
                    source: 'transfer',
                }); 
            }
            //IsApproval==1//审批
            if (IsApproval == 1) {
                // ns.openWin('chooseperson_frm', '请选择', {
                //     source: 'transfer',
                // });
                ns.openWin('chooseuser_frm', '选择审批人', {
                    source: 'transfer',
                }); 
            }

        },
        //移除抄送人
        guanbi_pic: function (id, IsApproval) {
            var that = this;
            that.chooseType = IsApproval;
            if (that.chooseType == 1) {
                that.choose_id_list = that.choose_id_list.filter((item) => {
                    return item.UserID != id
                });
            }
            if (that.chooseType == 0) {
                that.select_id_list = that.select_id_list.filter((item) => {
                    return item.UserID != id
                });
            }

        },
        // 抄送人
        select_person: function (select_list, type) {
            var that = this;
            if (type == 0) {
                for (var i = 0; i < select_list.length; i++) {
                    var item = select_list[i];
                    that.select_id_list.push(item);
                }
            } else {
                for (var i = 0; i < select_list.length; i++) {
                    var item = select_list[i];
                    that.choose_id_list.push(item);
                }
            }

            let obj = {};
            if (type == 0) {
                let peon = that.select_id_list.reduce((cur, next) => {
                    obj[next.UserID] ? "" : obj[next.UserID] = true && cur.push(next);
                    return cur;
                }, []);
                that.select_id_list = peon;
            } else {
                let peon = that.choose_id_list.reduce((cur, next) => {
                    obj[next.UserID] ? "" : obj[next.UserID] = true && cur.push(next);
                    return cur;
                }, []);
                that.choose_id_list = peon;
            }

        },
        //审批-上传附件
        do_openUp_ex: function () {
            var that = this;
            that.exshowup = true;
        },
        //上传图片
        add_picture_ex: function () {
            var that = this;
            that.exshowup = false;
            ns.confirmPer('camera', function () {
                that.choose_picture_start_ex();
            })
        },
        choose_picture_start_ex: function () {
            var that = this;
            if (that.exUploadList.length >= that.exmaxuploadcount) {
                api.toast({
                    msg: '最多支持' + that.exmaxuploadcount + '张图片',
                    duration: 2000,
                    location: 'bottom'
                });
                return;
            }
            api.actionSheet({
                cancelTitle: '取消',
                buttons: ['拍照', '从相册选择']
            }, function (ret, err) {
                //拍照
                if (ret.buttonIndex == 1) {
                    that.upload_choose_picture_ex();
                    return;
                }
                //从相册选择
                if (ret.buttonIndex == 2) {
                    that.choose_picture_album_ex();
                    return;
                }
                //取消 
                else {
                    return false;
                }
            });
        },
        upload_choose_picture_ex: function () {
            var that = this;
            api.getPicture({
                sourceType: 'camera',
                encodingType: 'jpg',
                destinationType: 'url',
                allowEdit: false,
                saveToPhotoAlbum: true,
            }, function (ret, err) {
                if (ret && ret.data) {
                    var list = [];
                    list.push({
                        url: ret.data,
                    });
                    const params = {
                        action: "uploadfileone",
                    }
                    ns.post(params, function (succeed, data, err) {
                        if (succeed) {
                            that.exUploadList.push(data.file);
                        }
                    }, {
                        files: {
                            file: list[0].url
                        }
                    })
                }
            });
        },
        choose_picture_album_ex: function () {
            var that = this;
            WXPhotoPicker.open({
                max: that.exmaxuploadcount - that.exUploadList.length,
                type: 'image',
            }, function (ret) {
                if (ret) {
                    if (ret.list.length > 0) {
                        ret.list.forEach((item) => {
                            var list = [];
                            list.push({
                                url: item.path,
                            });
                            const params = {
                                action: "uploadfileone",
                            }
                            ns.post(params, function (succeed, data, err) {
                                if (succeed) {
                                    that.exUploadList.push(data.file);
                                }
                            }, {
                                files: {
                                    file: list[0].url
                                }
                            })
                        });
                    }
                }
            });
        },
        //上传视频
        add_vedio_ex: function () {
            var that = this;
            that.exshowup = false;
            ns.confirmPer('camera', function () {
                that.choose_video_start();
            })
        },
        choose_video_start_ex: function () {
            var that = this;
            WXPhotoPicker.open({
                max: that.exmaxuploadcount - that.exUploadList.length,
                type: 'video',
            }, function (ret) {
                if (ret) {
                    if (ret.list.length > 0) {
                        ret.list.forEach((item) => {
                            var list = [];
                            list.push({
                                url: item.path,
                            });
                            const params = {
                                action: "uploadfileone",
                            }
                            ns.post(params, function (succeed, data, err) {
                                if (succeed) {
                                    that.exUploadList.push(data.file);
                                }
                            }, {
                                files: {
                                    file: list[0].url
                                }
                            })
                        });
                    }
                }
            });
        },
        // 播放视频
        open_video_ex: function (item) {
            var that = this;
            var module = api.require('easyVideoPlayer');
            var param = {
                msg: item.FilePath
            };
            api.download({
                url: item.FilePath,
                savePath: 'fs://app/' + item.FileName,
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {
                if (ret.state == 1) {
                    module.playVideo(param);
                }
            })
        },
        //上传文件
        add_wenjian_ex: function () {
            var that = this;
            that.exshowup = false;
            fileBrowser.open({
                confirm: true
            }, function (ret) {
                fileBrowser.close();
                // alert(JSON.stringify(ret))
                // alert(JSON.stringify(ret && ret.status))
                if (ret) {
                    const url = ret.url || ""
                    var i = url.lastIndexOf('.');
                    var j = url.length;
                    var wenjianName = url.slice(i + 1, j);
                    const params = {
                        action: "fileupload",
                    }
                    ns.post(params, function (succeed, data, err) {
                        if (succeed) {
                            if(data.imgs&&data.imgs.length>0){
                                that.exUploadList.push(data.imgs[0]);
                            }
                        }
                    }, {
                        files: {
                            file: [url]
                        }
                    })
                    return;
                }
                return false;
            });
        },
        open_flie_ex: function (item, index) {
            var that = this;
            var i = item.FileName.lastIndexOf('.');
            var j = item.FileName.length;
            var nameType = item.FileName.slice(i + 1, j);
            if (nameType == 'png' || nameType == 'jpg' || nameType == 'jpeg' || nameType == 'tif' || nameType == 'gif') {
                that.img_browser_ex(item.FilePath);
            } else if (nameType == 'mp4' || nameType == 'wmv' || nameType == 'rmvb' || nameType == 'avi') {
                that.open_video_ex(item);
            } else {
                that.do_openFile_ex(item);
            }
        },
        img_browser_ex: function (imgurl) {
            var that = this;
            var imgurls = [];
            imgurls.push(imgurl);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        do_openFile_ex: function (item) {
            api.download({
                url: item.FilePath,
                savePath: 'fs://app/' + item.FileName,
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {
                if (ret.state == 1) {
                    docReader.open({
                        path: ret.savePath,
                        autorotation: false
                    }, function (ret, err) {
                        if (ret.status) {
                            // alert(JSON.stringify(ret));
                        } else {
                            alert(JSON.stringify(err));
                        }
                    });
                } else {
                    api.toast({
                        msg: '打开失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }

            })
        },
        //删除文件
        do_delete_ex: function (id) {
            var that = this;
            that.exUploadList = that.exUploadList.filter((item) => {
                return item.ID != id
            });
        },

    }
});

apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    actionsheet = new auiActionsheet();
    imageBrowser = api.require('imageBrowser');
    fileBrowser = api.require('fileBrowser');
    docReader = api.require('docReader');
    WXPhotoPicker = api.require('WXPhotoPicker');
    // bmLocation = api.require('bmLocation');
    app.form.StaffID = api.pageParam.StaffID;
    app.get_outTypemsg();
    api.addEventListener({
        name: 'purchase_add'
    }, function (ret) {
        if (app.chooseType == 1) {
            var chooselist = ret.value.data;
            app.select_person(chooselist, 1);
            // app.choose_id_list=ret.value.data;
        }
        if (app.chooseType == 0) {

            var select_list = ret.value.data;
            app.select_person(select_list, 0);
        }

    })

    api.addEventListener({
        name: 'purchase_update'
    }, function (ret) {
        if (ret.value.type == 1) {
            app.choose_id_list = ret.value.data;
        }
        if (ret.value.type == 0) {
            app.select_id_list = ret.value.data;
        }

    })

    api.addEventListener({
        name: 'do_open_neibubaoshi'
    }, function (ret, err) {
        ns.openWin('purchase_list', '申请记录');
    });

};
